package com.monster.producor;

import com.lmax.disruptor.RingBuffer;
import com.monster.event.LongEvent;

/**
 * description:
 *
 * @author Yuanml on 2021/4/13 19:57
 */
public class LongEventProducer {
    private final RingBuffer<LongEvent> ringBuffer;
    public LongEventProducer(RingBuffer<LongEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void onData(long bb) {
        // 获取序列号
        long sequence = ringBuffer.next();
        try {
            // 获取序列号对应的实体元素
            LongEvent event = ringBuffer.get(sequence);
            // 修改元素的值
            event.setValue(bb);
        } finally {
            // 发布元素
            ringBuffer.publish(sequence);
        }
    }
}
